import numpy as np
# 按手机价格统计统计评分最大值，最小值，算术平均值，中位数
price= np.loadtxt(r"C:\Users\liuqing\Desktop\python\Mobile.csv",delimiter=",",usecols=(1,),dtype=float)
rating = np.loadtxt(r"C:\Users\liuqing\Desktop\python\Mobile.csv",delimiter=",",usecols=(2,),dtype=float)
print(price)
print(rating)
p_price = np.unique(price)
print(np.unique(price))
# 求数组的大小
p_size = p_price.size
print(p_size)
# 1457行，5列，存手机价格，评分最大值，最小值，算术平均值，中位数

price_rating = np.zeros([p_size,5])
j=0
# for i, p in enumerate(p_price):
for i in p_price:
    maprating = rating[price==i]
    price_rating[j,0] = i
    price_rating[j,1] = np.max(maprating) 
    price_rating[j,2] = np.min(maprating) 
    price_rating[j,3] = np.mean(maprating) 
    price_rating[j,4] = np.median(maprating) 
    j=j+1
print(price_rating)